package com.agent.membership.entity;

import com.agent.common.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * 会员订阅实体
 * @author Jeff_Wan
 * @description 存储用户订阅信息，包括套餐类型、订阅周期、有效期等
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("membership_subscription")
public class MembershipSubscription extends BaseEntity {
    /**
     * 用户ID
     */
    private Long userId;
    /**
     * 会员计划类型(FREE/BASIC/PRO/MAX)
     */
    private String planType;
    /**
     * 订阅类型(MONTHLY/YEARLY)
     */
    private String subscriptionType;
    /**
     * 订阅开始日期(UTC)
     */
    private LocalDateTime startDate;
    /**
     * 订阅到期日期(UTC)
     */
    private LocalDateTime expiryDate;
    /**
     * 是否自动续费(1:是,0:否)
     */
    private Boolean autoRenew;
    /**
     * 订阅状态(ACTIVE/EXPIRED/CANCELLED)
     */
    private String status;
    /**
     * 上次发放积分日期(UTC)
     */
    private LocalDateTime lastCreditIssuedDate;

    /**
     * 检查订阅是否有效
     * @return true-有效, false-过期
     */
    public boolean isActive() {
        return LocalDateTime.now(ZoneOffset.UTC).isBefore(expiryDate)
                && "ACTIVE".equals(status);
    }
}